package dream.zyp.ballgame.activity;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.SurfaceHolder;

import dream.zyp.ballgame.component.ViewInfo;

/**
 * Created by ZYP on 2017/3/4.
 */
public class ViewCallBack implements SurfaceHolder.Callback {
    private DrawThread thread;

    private ViewInfo viewInfo = null;

    private Handler controlHandler;

    private boolean flag = false;
    private Handler transmitHandler = new Handler()
    {
        /**
         * Subclasses must implement this to receive messages.
         *
         * @param msg
         */
        @Override
        public void handleMessage(Message msg) {
            if (flag){
                Message buffer = new Message();
                buffer.what = msg.what;
                controlHandler.sendMessage(buffer);
            }

        }
    };
    public ViewCallBack(ViewInfo viewInfo){
        this.viewInfo = viewInfo;
        thread = new DrawThread();
        thread.setViewInfo(viewInfo);
        controlHandler = thread.getControlHandler();
        flag = true;

    }
    @Override
    public void surfaceCreated(SurfaceHolder holder) {

//        thread = new DrawThread(holder);
//        thread.setViewInfo(viewInfo);
//        controlHandler = thread.getControlHandler();
//        flag = true;
//        thread.start();
        thread.setHolder(holder);
        thread.start();

    }


    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {

    }

    public Handler getTransmitHandler(){return transmitHandler;}
}
